package com.xms.schema.service.relationship;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.datacore.service.FinderService;
import com.xms.schema.entity.RelationShipView;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * RelationShipViewFinderService
 * </p>
 *
 * @author migo
 * @since 2021/9/16
 */
@CacheConfig(cacheNames = "schema.relationship", keyGenerator = "CacheKeyGenerator")
@Service
public class RelationShipViewFinderService extends FinderService<RelationShipView> implements IRelationShipViewFinderService{

    @Cacheable(condition="#id != null")
    @Override
    public RelationShipView getById(UUID id) {
        return super.getById(id);
    }

    @Cacheable(condition="#idList != null && #idList.size() > 0")
    @Override
    public List<RelationShipView> getByIds(Collection<UUID> idList) {
        return super.listByIds(idList);
    }

    @Cacheable()
    @Override
    public RelationShipView getOne(Wrapper<RelationShipView> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Cacheable()
    @Override
    public int count() {
        return super.count();
    }

    @Cacheable()
    @Override
    public int count(Wrapper<RelationShipView> queryWrapper) {
        return super.count(queryWrapper);
    }

    @Cacheable()
    @Override
    public List<RelationShipView> list(Wrapper<RelationShipView> queryWrapper) {
        return super.list(queryWrapper);
    }

    @Cacheable()
    @Override
    public List<RelationShipView> all() {
        return super.list();
    }

    @Cacheable(condition="#name != null")
    @Override
    public RelationShipView getByName(String name) {
        LambdaQueryWrapper<RelationShipView> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RelationShipView::getName, name);
        return super.getOne(queryWrapper);
    }

    @Cacheable(condition="#entityid != null")
    @Override
    public List<RelationShipView> getByReferencingEntityId(UUID entityid) {
        LambdaQueryWrapper<RelationShipView> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RelationShipView::getReferencingentityid, entityid);
        return super.list(queryWrapper);
    }

    @Cacheable(condition="#entityid != null")
    @Override
    public List<RelationShipView> getByReferencedEntityId(UUID entityid) {
        LambdaQueryWrapper<RelationShipView> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RelationShipView::getReferencedentityid, entityid);
        return super.list(queryWrapper);
    }
}
